package com.kgcx.price.rabbitmq;

import com.alibaba.fastjson.JSONObject;
import com.kgcx.common.rabbitmq.bean.Message;
import com.kgcx.common.rabbitmq.consts.ExchangeConst;
import com.kgcx.common.rabbitmq.consts.RoutingKeyConst;
import com.kgcx.price.domain.MileageLngLat;
import com.kgcx.price.domain.MileageRecord;
import com.kgcx.price.domain.TPriceCaculationRule;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author 吴刚林
 * @date 2017/11/20
 */
@Slf4j
@Component
public class BaseInfoProducer {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void addBaseInfoDriverLocation(MileageLngLat mileageLngLat) {
        log.info(String.format("新增司机坐标位置成功的MQ消息，司机id[%s]。", mileageLngLat.getDriverId()));
        Message msg = Message.buildMessage("positionDriver", Message.FLAG_ADD, mileageLngLat);
        rabbitTemplate.convertAndSend(ExchangeConst.OPC, RoutingKeyConst.OPC_COMMON, JSONObject.toJSONString(msg));
    }

    public void addBaseInfoCarLocation(MileageLngLat mileageLngLat) {
        log.info(String.format("新增车辆坐标位置成功的MQ消息，车辆id[%s]。", mileageLngLat.getCarId()));
        Message msg = Message.buildMessage("positionVehicle", Message.FLAG_ADD, mileageLngLat);
        rabbitTemplate.convertAndSend(ExchangeConst.OPC, RoutingKeyConst.OPC_COMMON, JSONObject.toJSONString(msg));
    }

    public void addBaseInfoCarDistance(MileageRecord mileageRecord) {
        log.info(String.format("新增车辆里程成功的MQ消息，车辆id[%s]。", mileageRecord.getCarId()));
        Message msg = Message.buildMessage("baseInfoVehicleTotalMile", Message.FLAG_ADD, mileageRecord);
        rabbitTemplate.convertAndSend(ExchangeConst.OPC, RoutingKeyConst.OPC_COMMON, JSONObject.toJSONString(msg));
    }

    public void addBaseInfoCaculationRule(TPriceCaculationRule tPriceCaculationRule) {
        log.info(String.format("新增车辆报价规则成功的MQ消息，报价[%s]。", tPriceCaculationRule.getKid()));
        Message msg = Message.buildMessage("baseInfoCompanyFare", Message.FLAG_ADD, tPriceCaculationRule);
        rabbitTemplate.convertAndSend(ExchangeConst.OPC, RoutingKeyConst.OPC_COMMON, JSONObject.toJSONString(msg));
    }
}
